import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

class TabBarViewPage extends StatelessWidget {
  const TabBarViewPage({super.key});

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 3, // Tab 数量
      child: Scaffold(
        appBar: AppBar(
          title: const Text('TabBarView 全属性示例'),
          bottom: const TabBar(
            tabs: [
              Tab(icon: Icon(Icons.home), text: '首页'),
              Tab(icon: Icon(Icons.message), text: '消息'),
              Tab(icon: Icon(Icons.settings), text: '设置'),
            ],
          ),
        ),
        body: const TabBarView(
          physics: const BouncingScrollPhysics(), // 滑动物理效果（可设置 NeverScrollableScrollPhysics 禁止滑动）
          dragStartBehavior: DragStartBehavior.start, // 手势行为（默认从触摸开始）
          children: const [
            _PageContent(color: Colors.blue, text: '首页内容'),
            _PageContent(color: Colors.green, text: '消息内容'),
            _PageContent(color: Colors.orange, text: '设置内容'),
          ],
        ),
      ),
    );
  }
}

class _PageContent extends StatelessWidget {
  final Color color;
  final String text;

  const _PageContent({required this.color, required this.text});

  @override
  StatelessElement createElement() {
    print('JtTag:节点创建:$text');
    return super.createElement();
  }

  @override
  Widget build(BuildContext context) {

    return Container(
      color: color.withOpacity(0.1),
      alignment: Alignment.center,
      child: Text(
        text,
        style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
      ),
    );
  }
}
